/**
 *  Copyright 2009 Henning Teek, Ingo Renner
 *  
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *  
 *  http://www.apache.org/licenses/LICENSE-2.0
 *  
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License. 
 */
package com.googlecode.chigs.repository;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import com.googlecode.chigs.domain.Attachment;
import com.googlecode.chigs.domain.ConfigLocation;
import com.googlecode.chigs.domain.ConfigLocationGroup;
import com.googlecode.chigs.domain.ConfigPair;
import com.googlecode.chigs.domain.ConfigRevision;
import com.googlecode.chigs.domain.ConfigValue;
import com.googlecode.chigs.domain.Configuration;
import com.googlecode.chigs.domain.Module;
import com.googlecode.chigs.domain.Product;
import com.googlecode.chigs.domain.Revision;
import com.googlecode.chigs.domain.Version;
import com.googlecode.chigs.web.common.ConfigurationStructureCreationException;

/**
 * @author Ingo Renner
 * @author Henning Teek
 */
public interface ChigsFacade {
	List<ConfigLocation> findConfigLocationsByEmptyGroup();
	
	void saveConfigLocationGroup(ConfigLocationGroup group);

	List<Module> loadModulesByProduct(Product product);

	void saveModule(Module modelObject);

	void saveVersion(Version modelObject);

	void saveRevision(Revision modelObject);

	Revision loadLatestRevision(Module module);

	void saveConfigRevision(ConfigRevision modelObject);

	ConfigRevision loadLatestConfigRevision(Configuration configuration);

	List<Attachment> loadAttachementsByRevison(Revision revision);

	List<Version> loadVersionsByProduct(Product product);

	List<Revision> loadRevisionsByModule(Module module);
	
	List<ConfigLocation> loadLocationsByVersion(Version version);

	String doImport(InputStream inputStream, byte[] md5sum);

	File getDataDir();
	
	File getDataFile(String digest);

	List<ConfigRevision> loadConfigRevisionsByConfiguration(Configuration configuration);

	List<Configuration> loadConfigurationsByProduct(Product product);

	List<ConfigPair> loadConfigPairsByRevision(Revision revision);

	long getModuleCountByProduct(Product product);

	long getConfigurationCountByProduct(Product product);

	List<ConfigValue> loadConfigValuesByConfigRevision(ConfigRevision configRevision);
	
	String toHexString(byte[] md5hashAsByteArray);
	
	File getTmpDir();
	
	File createFile(File file) throws IOException;
	
	File generateConfigurationFilestructure(ConfigRevision configRevision) throws ConfigurationStructureCreationException;
}
